import { InitModalMethod, ParseModalMethod } from './defination';

/**
 * 设置表单属性
 * @param { Object } form 表单数据
 * @param { Object } workstep cached的ai工作流
 */
export const initModalData = (form = {}, workstep = {}) => {
	if (!form || !workstep || !workstep.do) {
		return;
	}

	form.aiSpeak = workstep.do?.data; // 1
	form.waitTime = workstep.after?.data; // 2
	// yes
	form.nextStepYes = workstep.after?.after?.id;

	// 预录制视频属性
	form.aiSpeakVideo = workstep.do?.video;

	/** 变量存储处理开始 */
	form['aiSpeakVariableId'] = workstep.do.variableId;
	// form['aiSpeakVariables'] = workstep.do.variables?.filter(item => form['aiSpeak']?.indexOf(`{{${item.name}}}`) !== -1);
	form['aiSpeakVariables'] = workstep.do.variables;
	console.log(form['aiSpeakVariables'], 'aiSpeakVariables播报话术');
	/** 变量存储处理结束 */

	form.name = workstep.name;
};
InitModalMethod['speakWaiting'] = initModalData;
/**
 * 解析表单属性
 * @param { Object } form 表单数据
 * @param { Object } workstep cached的ai工作流
 */
export const parseModalData = (form = {}, workstep = {}) => {
	console.log(form, workstep);
	if (!form || !workstep || !workstep.do) {
		return;
	}
	workstep.do.data = form.aiSpeak; // 1
	workstep.after.data = form.waitTime; // 2
	// yes
	workstep.after.after.id = form.nextStepYes;
	workstep.after.id = form.nextStepYes;

	// 预录制视频属性
	workstep.do.video = form.aiSpeakVideo;

	/** 变量存储处理开始 */
	workstep.do.variableId = form['aiSpeakVariableId'];
	// workstep.do.variables = form['aiSpeakVariables']?.filter(item => form['aiSpeak'].indexOf(`{{${item.name}}}`) !== -1);
	workstep.do.variables = form['aiSpeakVariables'];
	console.warn(workstep.do.variables, '播报saveAiSpeakVariables');
	/** 变量存储处理结束 */
	workstep.name = form.name;
};
ParseModalMethod['speakWaiting'] = parseModalData;
// {
//     "name": "",
//     "do": {
//         "data": "1",
//         "command": "speak",
//         "variables": [],
//         "variableId": ""
//     },
//     "no": "speakWaiting_1",
//     "id": "speakWaiting_1",
//     "type": "speakWait",
//     "after": {
//         "data": 2,
//         "command": "wait",
//         "no": "BlankNode_2",
//         "id": "BlankNode_2",
//         "type": "yes",
//         "after": {
//             "command": "jump-to",
//             "no": "BlankNode_2",
//             "id": "BlankNode_2",
//             "type": "yes"
//         }
//     },
//     "completed": true,
//     "hasStartNode": false
// }
